﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using cocos2d;
using System.Threading;
namespace CampaignWP7
{
    public class ResDef
    {
        //texture
        public static string g_GameResPListFile = @"plist/MainGame";
        public static string g_GameResTextureFile = @"plist/images/MainGame";
        //
        public static string g_GameResBulletPListFile = @"plist/Bullet";
        public static string g_GameResBulletTextureFile = @"plist/images/Bullet";
        //
        public static string g_GameResWolfPListFile = @"plist/Wolf";
        public static string g_GameResWolfTextureFile = @"plist/images/Wolf";
        //
        public static string g_GameResGUIPListFile = @"plist/MainGUI";
        public static string g_GameResGUITextureFile = @"plist/images/MainGUI";
        //
        public static string g_GameResBalloonPListFile = @"plist/Balloon";
        public static string g_GameResBalloonTextureFile = @"plist/images/Balloon";
        //
        public static string g_GameResBunnyPListFile = @"plist/Bunny";
        public static string g_GameResBunnyTextureFile = @"plist/images/Bunny";
        //
        public static string g_GameResShieldPListFile = @"plist/Shield";
        public static string g_GameResShieldTextureFile = @"plist/images/Shield";
        //
        public static string g_GameResUFOPListFile = @"plist/UFO";
        public static string g_GameResUFOTextureFile = @"plist/images/UFO";
        //
        public static string g_BlankTextureFile = @"images/blank";
        //
        public static CCSpriteBatchNode g_WolfBatchNode = new CCSpriteBatchNode();
        public static CCSpriteBatchNode g_BulletBatchNode = new CCSpriteBatchNode();
        public static CCSpriteBatchNode g_BalloonBatchNode = new CCSpriteBatchNode();
        public static CCSpriteBatchNode g_BunnyBatchNode = new CCSpriteBatchNode();
        public static CCSpriteBatchNode g_ShieldBatchNode = new CCSpriteBatchNode();
        public static CCSpriteBatchNode g_UFOBatchNode = new CCSpriteBatchNode();

        //music
        public static string g_BalloonBomb = @"music/Bomb";
        public static string g_BunnyFire = @"music/Fire";
        public static string g_BackgroundMusic = @"music/PigAndWolf";

        public enum WeatherType { WT_Sun = 0,WT_Rain };
        public static Dictionary< WeatherType, List<CCSpriteFrame> > g_WeatherDict;    

        public static void  initRes(out int progress)
        {
            //CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile(ResDef.g_GameResPListFile);
            //
            CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile(ResDef.g_GameResBulletPListFile);
            CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile(ResDef.g_GameResWolfPListFile);
            CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile(ResDef.g_GameResBalloonPListFile);
            CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile(ResDef.g_GameResBunnyPListFile);
            CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile(ResDef.g_GameResShieldPListFile);
            CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile(ResDef.g_GameResUFOPListFile);
            progress = 10;
            Thread.Sleep(100);
            //
            g_WolfBatchNode = CCSpriteBatchNode.batchNodeWithFile(g_GameResWolfTextureFile);
            progress = 20;
            Thread.Sleep(100);

            //
            g_BulletBatchNode = CCSpriteBatchNode.batchNodeWithFile(g_GameResBulletTextureFile);
            progress = 30;
            Thread.Sleep(100);

            //
            g_BalloonBatchNode = CCSpriteBatchNode.batchNodeWithFile(g_GameResBalloonTextureFile);
            progress = 40;
            Thread.Sleep(100);

            //
            g_BunnyBatchNode = CCSpriteBatchNode.batchNodeWithFile(g_GameResBunnyTextureFile);
            progress = 50;
            Thread.Sleep(100);

            //
            g_ShieldBatchNode = CCSpriteBatchNode.batchNodeWithFile(g_GameResShieldTextureFile);
            progress = 60;
            Thread.Sleep(100);

            //
            g_UFOBatchNode = CCSpriteBatchNode.batchNodeWithFile(g_GameResUFOTextureFile);
            progress = 70;
            Thread.Sleep(100);

            //weather frames
            {
                g_WeatherDict = new Dictionary<WeatherType, List<CCSpriteFrame>>();
                string filePath = @"Weather/";
                string fileExt = ".png";
                string rainFileTitle = "rain_";
                List<CCSpriteFrame> m_rainFrams = new List<CCSpriteFrame>(4);
                //
                CCTexture2D texture_0 = CCTextureCache.sharedTextureCache().addImage(@"Weather/rain_0");
                texture_0.Name = 1;
                CCSpriteFrame frame_0 = CCSpriteFrame.frameWithTexture(texture_0, new CCRect(0, 0, texture_0.PixelsWide, texture_0.PixelsHigh));
                m_rainFrams.Add(frame_0);

                CCTexture2D texture_1 = CCTextureCache.sharedTextureCache().addImage(@"Weather/rain_1");
                texture_1.Name = 2;
                CCSpriteFrame frame_1 = CCSpriteFrame.frameWithTexture(texture_1, new CCRect(0, 0, texture_1.PixelsWide, texture_1.PixelsHigh));
                m_rainFrams.Add(frame_1);

                CCTexture2D texture_2 = CCTextureCache.sharedTextureCache().addImage(@"Weather/rain_2");
                texture_2.Name = 3;
                CCSpriteFrame frame_2 = CCSpriteFrame.frameWithTexture(texture_2, new CCRect(0, 0, texture_2.PixelsWide, texture_2.PixelsHigh));
                m_rainFrams.Add(frame_2);

                CCTexture2D texture_3 = CCTextureCache.sharedTextureCache().addImage(@"Weather/rain_3");
                texture_3.Name = 4;
                CCSpriteFrame frame_3 = CCSpriteFrame.frameWithTexture(texture_3, new CCRect(0, 0, texture_3.PixelsWide, texture_3.PixelsHigh));
                m_rainFrams.Add(frame_3);
                //last
                g_WeatherDict.Add(WeatherType.WT_Rain, m_rainFrams);               
                
            }
            progress = 100;

        }
        public static void RemoveAllBatchNodeChildren()
        {
            g_WolfBatchNode.removeAllChildrenWithCleanup(true);
            g_BulletBatchNode.removeAllChildrenWithCleanup(true);
            g_BalloonBatchNode.removeAllChildrenWithCleanup(true);
            g_BunnyBatchNode.removeAllChildrenWithCleanup(true);
            g_ShieldBatchNode.removeAllChildrenWithCleanup(true);
            g_UFOBatchNode.removeAllChildrenWithCleanup(true);
        }


    }
    
}